/*
 * Copyright (C) 2021 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.android.accessibility.braille.brailledisplay.controller.utils;

import android.os.Build;

/** Utils for display module. */
public class Utils {

  private Utils() {}

  public static boolean isRobolectric() {
    return "robolectric".equals(Build.FINGERPRINT);
  }

  /**
   * Convert byte[] to space-separated String of hex-encoded bytes. Useful for debugging.
   *
   * @param bytes the bytes, must be non-null
   * @param count the number of bytes to convert
   * @return bytes as String
   */
  public static String bytesToString(byte[] bytes, int count) {
    StringBuilder sb = new StringBuilder();
    if (count > bytes.length) {
      throw new IllegalArgumentException(
          String.format("byte array has length %d; cannot process %d bytes", bytes.length, count));
    }
    for (int i = 0; i < count; i++) {
      sb.append(String.format("%02X", bytes[i]));
      if (i < count - 1) {
        sb.append(" ");
      }
    }
    return sb.toString();
  }
}
